package cn.school.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import cn.school.dao.SubjectDao;
import cn.school.entity.Subject;
import cn.school.util.MyBatisUtil;

public class SubjectService {
	public static int PAGE_SIZE = 5;

	public List<Subject> search(int pageNo) {
		SqlSession s = MyBatisUtil.get();
		try {
			SubjectDao studentDao = s.getMapper(SubjectDao.class);
			return studentDao.search(pageNo, PAGE_SIZE);
		} finally {
			MyBatisUtil.close(s);
		}
	}

	public int total() {
		SqlSession s = MyBatisUtil.get();
		try {
			SubjectDao studentDao = s.getMapper(SubjectDao.class);
			int t = studentDao.total();
			return t / PAGE_SIZE + (t % PAGE_SIZE == 0 ? 0 : 1);
		} finally {
			MyBatisUtil.close(s);
		}
	}
}
